<?php

/**
 * 
 *
 * @author Anthony Straetman
 *
 */

class LoginDB
{
	public static function login($email, $password) {
            if($password == LoginDB::getPassword($email))
                PlonkSession::set ('id', LoginDB::getId ($email));
            else
                throw new IncorrectPasswordException ();
	}
        
        public static function getPassword($email) {
            $db = PlonkWebsite::getDB();
            $password = $db->retrieveOne(sprintf('SELECT password FROM users WHERE email="%s"', $email));
            if(sizeof($password) == 0)
                throw new UserNotFoundException();
            else
                return $password['password'];
        }
        
        public static function getId($email) {
            $db = PlonkWebsite::getDB();
            $id = $db->retrieveOne(sprintf('SELECT id FROM users WHERE email="%s"', $email));
            if(sizeof($id) == 0)
                throw new UserNotFoundException();
            else
                return $id['id'];
        }
}

// EOF